package com.xkdx.guangguang.fragment.shop.brandofshop;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.Shop;

public class BrandSearchModule extends AbsModule {
	List<Shop> list;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("searchListGet")) {
					list = parseSearchList(jsonObj.getJSONObject("DetailInfo"));
				}

			}
		} catch (Exception e) {
			throw e;
		}
	}

	private List<Shop> parseSearchList(JSONObject person) throws Exception {
		ArrayList<Shop> list = new ArrayList<Shop>();
		try {
			String state = person.getString("StatusCode");
			if (state.equals("1")) {
				JSONArray jsonArray = (JSONArray) person
						.getJSONArray("DetailInfo");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject item = (JSONObject) jsonArray.opt(i);
					Shop shop = new Shop();
					shop.setLogo(item.getString("Logo"));
					shop.setShopID(item.getString("ShopID"));
					shop.setShopName(item.getString("ShopName"));
					shop.setBrandID(item.getString("BrandID"));
					shop.setShopType(item.getString("ShopType"));
					shop.setCard(item.getString("Card"));
					shop.setNewProductCount(item.getString("NewProductCount"));
					shop.setDiscountCount(item.getString("DiscountCount"));
					list.add(shop);

				}
			}

		} catch (Exception e) {
			throw e;
		}

		return list;
	}

}
